home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp95 / freyja13.exe / lha / LIBASM.ASM < prev    next >
Assembly Source File  |  1992-03-22  |  10KB  |  606 lines

  1. ; LIBASM.ASM -- Assembly Language DOS Interface Routines
  2. ;    Turbo C/ANSI Version, assumes Small model (64K code, separate 64K data)
  3. ;    Written April 1991 by Craig A. Finseth
  4.  
  5. ; -------------------- Constants and Macros --------------------
  6.  
  7. TRUE    equ    255
  8. FALSE    equ    0
  9. NUL    equ    0
  10. BEL    equ    7
  11. CR    equ    13
  12. LF    equ    10
  13. SPACE    equ    32
  14.  
  15. ; C function call stack layout -- SI, DI, BP, and SP must be preserved
  16.  
  17. old_bp    equ    0
  18. ret_addr equ    2
  19. arg1    equ    4
  20. arg2    equ    6
  21. arg3    equ    8
  22. arg4    equ    10
  23. arg5    equ    12
  24. arg6    equ    14
  25. arg7    equ    16
  26. arg8    equ    18
  27.  
  28. ; "safe" stack layout -- BP is not saved
  29.  
  30. sret_addr equ    0
  31. sarg1    equ    2
  32. sarg2    equ    4
  33. sarg3    equ    6
  34. sarg4    equ    8
  35. sarg5    equ    10
  36. sarg6    equ    12
  37. sarg7    equ    14
  38. sarg8    equ    16
  39.  
  40. clear    macro    x
  41.     xor        x,x
  42.     endm
  43.  
  44. zero    macro    x
  45.     xor        x,x
  46.     endm
  47.  
  48. testz    macro    x
  49.     or        x,x
  50.     endm
  51.  
  52. ; -------------------- Data Segment --------------------
  53.  
  54. _DATA    segment    word public 'DATA'    ; initialized data
  55.  
  56.     extrn    _t_attrib : byte    ; video attribute to use
  57.  
  58. iscolor    db    FALSE
  59. wastext    db    TRUE
  60. _DATA    ends
  61.  
  62. _BSS    segment    word public 'BSS'        ; uninitialized data
  63. oldmode    db    ?
  64. cursor_def dw    ?
  65. _BSS    ends
  66.  
  67. DGROUP    group    _DATA, _BSS
  68.     assume    ds:DGROUP
  69.  
  70. ; -------------------- Code Segment --------------------
  71.  
  72. _TEXT    segment    byte public 'CODE'
  73.     assume    cs:_TEXT
  74.  
  75.     public    _BlockAlloc, _BlockFree, _BlockGet, _BlockPut
  76.     public    _c_service
  77.     public    _JFiniA, _JInitA, _JGetKeyA, _JIsKeyA, _JLightOff, _JLightOn,
  78.     public    _JPushKeyA
  79.     public    _lseeka, _PSystem
  80.     public    _VidInit, _VidFini, _VidBell, _VidChar, _VidClear, _VidCursor
  81.     public    _VidCurOff, _VidCurOn
  82.  
  83. ; ------------------------------------------------------------
  84.  
  85. ; Allocate a block of memory and return the starting paragraph number
  86. ; or zero.
  87.  
  88. ;    unsigned
  89. ;    BlockAlloc(unsigned para)
  90. ;    C Callable
  91.  
  92. _BlockAlloc proc near
  93.     mov    BX,SP
  94.     mov    BX,[BX] + sarg1
  95.     mov    DX,BX        ; save a copy
  96.     mov    AH,48H
  97.     clc
  98.     int    21H
  99.     jc    alloc_no
  100.     cmp    BX,DX
  101.     jne    alloc_no
  102.     ret
  103. alloc_no: zero    AX
  104.     ret
  105. _BlockAlloc endp
  106.  
  107.  
  108. ; ------------------------------------------------------------
  109.  
  110. ; Free a block of memory.
  111.  
  112. ;    void
  113. ;    BlockFree(unsigned para)
  114. ;    C Callable
  115.  
  116. _BlockFree proc    near
  117.     mov    BX,SP
  118.     mov    BX,[BX] + sarg1
  119.     mov    ES,BX
  120.     mov    AH,49H
  121.     int    21H
  122.     ret
  123. _BlockFree endp
  124.  
  125.  
  126. ; ------------------------------------------------------------
  127.  
  128. ; Get a block of data from high memory.
  129.  
  130. ;    void
  131. ;    BlockGet(char *to, char huge *from, int len)
  132. ;    C Callable
  133.  
  134. ;    do    {
  135. ;        *to++ = *from++;
  136. ;        } while (--len > 0);
  137.  
  138. _BlockGet proc    near
  139.     push    BP
  140.     mov    BP,SP
  141.     push    DI
  142.     push    SI
  143.     push    DS
  144.     push    ES
  145.  
  146.     mov    DI,[BP] + arg1        ; to
  147.     mov    AX,DS            ;  & segment
  148.     mov    ES,AX
  149.  
  150.     mov    SI,[BP] + arg2        ; from
  151.     mov    AX,[BP] + arg3        ;  & segment
  152.     mov    DS,AX
  153.  
  154.     mov    CX,[BP] + arg4        ; CX is len
  155.     cld
  156.  
  157. ;mloop:    mov    AL,DS:[SI]        ; *from++
  158. ;    inc    SI
  159. ;    mov    ES:[DI],AL        ; *to++ =
  160. ;    inc    DI
  161. ;    loop    mloop            ; while --len>0
  162.  
  163.     rep    movsb
  164.  
  165.     pop    ES
  166.     pop    DS
  167.     pop    SI
  168.     pop    DI
  169.     pop    BP
  170.     ret
  171. _BlockGet endp
  172.  
  173.  
  174. ; ------------------------------------------------------------
  175.  
  176. ; Put a block of data into high memory.
  177.  
  178. ;    void
  179. ;    BlockPut(char huge *to, char *from, int len)
  180. ;    C Callable
  181.  
  182. ;    do    {
  183. ;        *to++ = *from++;
  184. ;        } while (--len > 0);
  185.  
  186. _BlockPut proc    near
  187.     push    BP
  188.     mov    BP,SP
  189.     push    DI
  190.     push    SI
  191.     push    ES
  192.  
  193.     mov    DI,[BP] + arg1        ; to
  194.     mov    AX,[BP] + arg2        ;  & segment
  195.     mov    ES,AX
  196.  
  197.     mov    SI,[BP] + arg3        ; from
  198.  
  199.     mov    CX,[BP] + arg4        ; CX is len
  200.     cld
  201.  
  202. ;mloop:    mov    AL,DS:[SI]        ; *from++
  203. ;    inc    SI
  204. ;    mov    ES:[DI],AL        ; *to++ =
  205. ;    inc    DI
  206. ;    loop    mloop            ; while --len>0
  207.  
  208.     rep    movsb
  209.  
  210.     pop    ES
  211.     pop    SI
  212.     pop    DI
  213.     pop    BP
  214.     ret
  215. _BlockPut endp
  216.  
  217.  
  218. ; ------------------------------------------------------------
  219.  
  220. ; Link to Jaguar special services.
  221.  
  222. _c_service proc near
  223.     push    BP
  224.     mov    BP,SP
  225.     xchg    DI,[BP+4]
  226.     pop    BP
  227.     int    60H
  228.     ret
  229. _c_service endp
  230.  
  231.  
  232. ; ------------------------------------------------------------
  233.  
  234. ; Terminate any special HP95LX processing.
  235.  
  236. ;    void
  237. ;    JFiniA(void)
  238. ;    C Callable
  239.  
  240. _JFiniA    proc    near
  241.     mov    AH,4AH        ; turn on serial port power
  242.     mov    AL,1
  243.     int    15H
  244.     ret
  245. _JFiniA    endp
  246.  
  247.  
  248. ; ------------------------------------------------------------
  249.  
  250. ; Initialize any special HP95LX processing.
  251.  
  252. ;    void
  253. ;    JInitA(void)
  254. ;    C Callable
  255.  
  256. _JInitA    proc    near
  257.     mov    AH,4AH        ; turn off serial port power
  258.     zero    AL
  259.     int    15H
  260.     ret
  261. _JInitA    endp
  262.  
  263.  
  264. ; ------------------------------------------------------------
  265.  
  266. ; Return the next key.  HP95LX specific.
  267.  
  268. ;    int
  269. ;    JGetKeyA(void)
  270. ;    C Callable
  271.  
  272. _JGetKeyA proc    near
  273.     mov    AH,10H
  274.     int    16H
  275.     ret
  276. _JGetKeyA endp
  277.  
  278.  
  279. ; ------------------------------------------------------------
  280.  
  281. ; Return non-zero if a key is available or zero if not.  HP95LX specific.
  282.  
  283. ;    int
  284. ;    JIsKeyA(void)
  285. ;    C Callable
  286.  
  287. _JIsKeyA proc    near
  288.     mov    AH,11H
  289.     int    16H
  290.     jz    jik_none
  291.     mov    AX,1
  292.     ret
  293. jik_none: zero    AX
  294.     ret
  295. _JIsKeyA endp
  296.  
  297.  
  298. ; ------------------------------------------------------------
  299.  
  300. ; Turn off the light sleep mode when checking the key press status.
  301. ; HP95LX specific.
  302.  
  303. ;    void
  304. ;    JLightOff(void)
  305. ;    C Callable
  306.  
  307. _JLightOff proc    near
  308.     mov    AX,4E00H
  309.     int    15H
  310.     ret
  311. _JLightOff endp
  312.  
  313.  
  314. ; ------------------------------------------------------------
  315.  
  316. ; Turn on the light sleep mode when checking the key press status.
  317. ; HP95LX specific.
  318.  
  319. ;    void
  320. ;    JLightOn(void)
  321. ;    C Callable
  322.  
  323. _JLightOn proc    near
  324.     mov    AX,4E01H
  325.     int    15H
  326.     ret
  327. _JLightOn endp
  328.  
  329.  
  330. ; ------------------------------------------------------------
  331.  
  332. ; Push the specified key into the input buffer.  HP95LX specific.
  333.  
  334. ;    void
  335. ;    JPushKeyA(int key)
  336. ;    C Callable
  337.  
  338. _JPushKeyA proc    near
  339.     push    BP
  340.     mov    BP,SP
  341.     mov    CX,[BP] + arg1
  342.     mov    AH,05H
  343.     int    16H
  344.     pop    BP
  345.     ret
  346. _JPushKeyA endp
  347.  
  348.  
  349. ; ------------------------------------------------------------
  350.  
  351. ;    long
  352. ;    lseeka(int fd, long dist, int mode)
  353. ;    C callable
  354.  
  355. _lseeka    proc        near
  356.         mov        BX,SP
  357.         mov        DX,[BX] + sarg2
  358.         mov        CX,[BX] + sarg3
  359.         mov        AX,[BX] + sarg4
  360.         mov        AH,42H
  361.         mov        BX,[BX] + sarg1
  362.         int        21H
  363.         jnc        lseek_a
  364.         mov        DX,-1
  365.         neg        AX
  366. lseek_a:    ret
  367. _lseeka    endp
  368.  
  369.  
  370. ; ------------------------------------------------------------
  371.  
  372. ;    int
  373. ;    PSystem(int AH, ...) /* int DX, int CX, int BX, int AL, int SI, int DI */
  374. ;    C callable
  375. ;    Note:  if the carry flag is set, the return code is negated
  376.  
  377. _PSystem proc    near
  378.     push    BP
  379.     mov    BP,SP
  380.     push    DI
  381.     push    SI
  382.  
  383.     mov    AX,[BP] + arg5        ; AL
  384.     mov    BX,[BP] + arg1        ; AH
  385.     mov    AH,BL
  386.     mov    DX,[BP] + arg2
  387.     mov    CX,[BP] + arg3
  388.     mov    BX,[BP] + arg4
  389.     mov    SI,[BP] + arg6
  390.     mov    DI,[BP] + arg7
  391.  
  392.     clc
  393.     int    21H
  394.     jnc    psyst_ok
  395.     neg    AX
  396.     pop    SI
  397.     pop    DI
  398.     pop    BP
  399.     ret
  400.  
  401. psyst_ok: and    AX,7FFFH
  402.     pop    SI
  403.     pop    DI
  404.     pop    BP
  405.     ret
  406. _PSystem endp
  407.  
  408.  
  409. ; ------------------------------------------------------------
  410.  
  411. ; Initialize the screen to 80x25 text mode.  Used (needed) for direct
  412. ; memory output only.
  413.  
  414. ;    int
  415. ;    VidInit(void)
  416. ;    C callable
  417.  
  418. _VidInit proc    near
  419.     int    11H            ; equipment check
  420.     and    AL,30H
  421.     cmp    AL,30H
  422.     jz    vidi_mret        ; monochome display
  423.  
  424.     mov    iscolor,TRUE
  425.  
  426.     mov    AH,0FH        ; get current video mode
  427.     int    10H
  428.     cmp    AL,2            ; 80x25 BW
  429.     jz    vidi_cret
  430.     cmp    AL,3            ; 80x25 color
  431.     jz    vidi_cret
  432.  
  433.     mov    oldmode,AL    ; save old mode
  434.     mov    wastext,FALSE
  435.     mov    AX,0002H        ; set to mode 2, 80x25 BW
  436.     int    10H
  437.  
  438. vidi_cret:
  439.     mov    CX,0007H
  440.     mov    cursor_def,CX
  441.  
  442.     mov    AX,0B800H    ; color base
  443.     ret
  444.  
  445. vidi_mret:
  446.     mov    CX,000CH
  447.     mov    cursor_def,CX
  448.  
  449.     mov    AX,0B000H    ; monochrome base
  450.     ret
  451. _VidInit endp
  452.  
  453.  
  454. ; ------------------------------------------------------------
  455.  
  456. ; Restore the screen.  Used (needed) for direct memory output only.
  457.  
  458. ;    void
  459. ;    VidFini(void)
  460. ;    C callable
  461.  
  462. _VidFini proc    near
  463.     test    iscolor,0FFH
  464.     jz    vidf_ret
  465.     test    wastext,0FFH
  466.     jnz    vidf_ret
  467.  
  468.     mov    AH,0            ; put old mode back
  469.     mov    AL,oldmode
  470.     int    10H
  471. vidf_ret: ret
  472. _VidFini endp
  473.  
  474.  
  475. ; ------------------------------------------------------------
  476.  
  477. ; Ring the bell.  Usable for both BIOS and direct memory output.
  478.  
  479. ;    void
  480. ;    VidBell(void)
  481. ;    C callable
  482.  
  483. _VidBell proc    near
  484.     mov    AL,BEL
  485.     zero    BL
  486.     mov    AH,14        ; write TTY
  487.     int    10H
  488.     ret
  489. _VidBell endp
  490.  
  491.  
  492. ; ------------------------------------------------------------
  493.  
  494. ; Write the specified character to the current cursor location. 
  495. ; Usable for BIOS output only.
  496.  
  497. ;    void
  498. ;    VidChar(char char)
  499. ;    C callable
  500.  
  501. _VidChar proc    near
  502.     push    BP
  503.     mov    BP,SP
  504.  
  505.     mov    AL,[BP] + arg1
  506.     zero    BH            ; page
  507.     mov    BL,_t_attrib
  508.     mov    CX,1            ; repeat count
  509.  
  510.     mov    AH,9            ; write char and attribute
  511.     int    10H
  512.     pop    BP
  513.     ret
  514. _VidChar endp
  515.  
  516.  
  517. ; ------------------------------------------------------------
  518.  
  519. ; Clear the next COUNT characters.  Usable for BIOS output only.
  520.  
  521. ;    void
  522. ;    VidClear(int count)
  523. ;    C callable
  524.  
  525. _VidClear proc    near
  526.     push    BP
  527.     mov    BP,SP
  528.  
  529.     mov    AL,SPACE
  530.     zero    BH            ; page
  531.     mov    BL,_t_attrib
  532.     mov    CX,[BP] + arg1        ; repeat count: # of char to clear
  533.     test    CX,0FFFFH
  534.     jz    vidc_ret
  535.  
  536.     mov    AH,9            ; write char and attribute
  537.     int    10H
  538. vidc_ret:
  539.     pop    BP
  540.     ret
  541. _VidClear endp
  542.  
  543.  
  544. ; ------------------------------------------------------------
  545.  
  546. ; Set the cursor to the specified row/column.  Usable for both BIOS
  547. ; and direct memory output.
  548.  
  549. ;    void
  550. ;    VidCursor(int row, int col)
  551. ;    C callable
  552.  
  553. _VidCursor proc    near
  554.     push    BP
  555.     mov    BP,SP
  556.  
  557.     mov    CL,[BP] + arg1
  558.     mov    DL,[BP] + arg2        ; col
  559.     mov    DH,CL            ; row
  560.  
  561.     zero    BH            ; page
  562.     mov    AH,2            ; set cursor position
  563.     int    10H
  564.     pop    BP
  565.     ret
  566. _VidCursor endp
  567.  
  568.  
  569. ; ------------------------------------------------------------
  570.  
  571. ; Tur the cursor off.
  572.  
  573. ;    void
  574. ;    VidCurOff(void)
  575. ;    C callable
  576.  
  577. _VidCurOff proc near
  578.     mov    AH,1        ; set cursor size
  579.     mov    CX,0FF00H
  580.     int    10H
  581.     ret
  582. _VidCurOff endp
  583.  
  584.  
  585. ; ------------------------------------------------------------
  586.  
  587. ; Set the cursor to a block cursor.
  588.  
  589. ;    void
  590. ;    VidCurOn(void)
  591. ;    C callable
  592.  
  593. _VidCurOn proc near
  594.     mov    AH,1        ; set cursor size
  595.     mov    CX,cursor_def
  596.     int    10H
  597.     ret
  598. _VidCurOn endp
  599.  
  600.  
  601. _TEXT    ends
  602.  
  603.         end
  604.  
  605. ; end of LIBASM.ASM -- Assembly Language DOS Interface Routines
  606.